# Maintainer: Justin Kromlinger <hashworks@archlinux.org>

pkgname=opensearch-geospatial-plugin
pkgver=2.11.0.0
pkgrel=1
_opensearchver=2.11.0
_jdkver=11
pkgdesc="OpenSearch Geospatial Plugin"
arch=('loong64' 'x86_64')
url="https://opensearch.org/docs/latest/dashboards/geojson-regionmaps/"
license=('Apache')
depends=("opensearch=${_opensearchver}")
makedepends=("java-environment=${_jdkver}" 'unzip')
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/opensearch-project/geospatial/archive/${pkgver}.tar.gz"
)
sha256sums=('c6d094b1949211b3cf242d1b3658fdc55de56eb3382ab29a08e3b781edf7d0c8')

build() {
  cd "geospatial-${pkgver}"
  export JAVA_HOME="/usr/lib/jvm/java-${_jdkver}-openjdk"
  export PATH="/usr/lib/jvm/java-${_jdkver}-openjdk/bin:$PATH"
  export GRADLE_OPTS="-Dbuild.snapshot=false -Dopensearch.version=${_opensearchver}"
  ./gradlew build \
    --exclude-task ":jacocoTestReport" \
    --exclude-task ":jacocoTestCoverageVerification"
}

package() {
  install -dm755 "${pkgdir}/usr/share/opensearch/plugins/opensearch-geospatial"
  cd "${pkgdir}/usr/share/opensearch/plugins/opensearch-geospatial"
  unzip "${srcdir}/geospatial-${pkgver}/build/distributions/opensearch-geospatial-${pkgver}.zip"

  install -Dm644 "${srcdir}/geospatial-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
